const Koa = require('koa')
const path = require('node:path')
const koaStatic = require('koa-static')
const bodyParser = require('koa-bodyparser')

const wrapper = require('./middleware/wrapper')
const errorHandler = require('./error/index')

const cdkRouter = require('./router/cdk.router')
const fileRouter = require('./router/file.router')
const orderRouter = require('./router/order.router')
const questionRouter = require('./router/question.router')
const rechargeRouter = require('./router/recharge.router')
const stadiumRouter = require('./router/stadium.router')
const userRouter = require('./router/user.router')
const staticRouter = require('./router/static.router')

const app = new Koa()

app.use(bodyParser())
app.use(koaStatic('./static'))

app.use(cdkRouter.routes()) // 兑换码模块的路由
app.use(fileRouter.routes()) // 文件模块的路由
app.use(orderRouter.routes()) // 订单模块的路由
app.use(questionRouter.routes()) // 客服模块的路由
app.use(rechargeRouter.routes()) // 充值模块的路由
app.use(stadiumRouter.routes()) // 场馆模块的路由
app.use(userRouter.routes()) // 用户模块的路由
app.use(staticRouter.routes()) // 映射静态文件夹的路由 => 用于访问静态文件

app.on('error', errorHandler)
app.use(wrapper)


module.exports = app